#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;


int triangleNumber(vector<int>& nums) {
    sort(nums.begin(), nums.end());
    int n = nums.size();
    int count = 0;
    for (int max = n - 1; max >= 2; max--) {
        int left = 0, right = max - 1;
        while (left < right) {
            if (nums[left] + nums[right] > nums[max]) {
                count += right - left;
                right--;
            }
            else
                left++;
        }
    }
    return count;
}
int main()
{
    vector<int> nums = { 2,2,3,4 };
    triangleNumber(nums);
    return 0;
}